function class(className, super)
    local clazz = {__cname = className, super = super}
    if super then
        -- 有继承设置继承
        setmetatable(clazz, super)
        super.__index = super
    end

    clazz.new = function(...)
        -- 构造函数,创建实例
        local instance = {}
        -- 实例关联到类
        setmetatable(instance, clazz)
        clazz.__index = clazz

        -- ctor为自定义构造函数,如果定义则执行
        if clazz.ctor then clazz.ctor(instance, ...) end

        -- 设置父类
        instance.class = clazz

        -- 实现通用InstanceOf
        instance.InstanceOf = function(target)
            if instance.class == target then return true end
            local cur = instance.class
            while cur.super do
                cur = cur.super
                if cur == target then return true end
            end
            return false
        end

        return instance
    end
    
    return clazz
end
